var my={
	version:'1.0'
};
//测试
//var config={
//	domain:'http://192.168.1.10:8082/', //域名
//  url:'http://192.168.1.10:8083/',    //图片路径
//	url_car:'http://192.168.1.10:8087/',//图片路径
//	danwei:'￥'                        //单位
//}
//正式
var config={
	domain:'http://webapp-api.aircnc.com.cn/',//域名
	url:'http://img1.aircnc.com.cn/',    //图片路径
	url_car:'http://img2.aircnc.com.cn/',//图片路径
	danwei:'￥'
}
api={
    	sendmobilecode:config.domain+"userabout/mobilecode/sendmobilecode.htm", //获取验证码接口
    	userlogin:config.domain+"userabout/user/userlogin.htm",//登陆接口
    	userregister:config.domain+"userabout/user/userregister.htm",//注册接口
    	useraccountinfo:config.domain+"userabout/user/useraccountinfo.htm",//用户中心详情接口
    	withdrawals:config.domain+"userabout/user/withdrawals.htm",//提现接口
    	getbankcard:config.domain+"userabout/user/getbankcard.htm",//提现卡获取接口
    	getaccountdetails:config.domain+"userabout/user/getaccountdetails.htm",//交易明细接口

        useridentityinfo:config.domain+"userabout/orderelated/useridentityinfo.htm",//身份认证详情接口
        useridentity:config.domain+"userabout/user/useridentity.htm",//验证身份接口

        usercarlist:config.domain+"userabout/user/usercarlist.htm",//返回入驻车辆接口
        getcarsinfo:config.domain+"userabout/user/getcarsinfo.htm",//返回入驻车辆信息接口
        userdelcarimg:config.domain+"userabout/orderelated/userdelcarimg.htm",//删除车辆图片接口
        usercardelete:config.domain+"userabout/user/usercardelete.htm",//删除入驻车辆接口
        uploadcarimg:config.domain+"userabout/user/uploadcarimg.htm",//添加车辆照片接口
        usercarsmanage:config.domain+"userabout/user/usercarsmanage.htm",//入驻车辆认证接口

        userbankcardlist:config.domain+"userabout/orderelated/userbankcardlist.htm",//获取银行卡信息接口
        userbankcarddelte:config.domain+"userabout/orderelated/userbankcarddelte.htm",//删除银行卡信息接口
        useraddbankcard:config.domain+"userabout/orderelated/useraddbankcard.htm",//验证添加银行卡接口

        userupdatepassword:config.domain+"userabout/user/userupdatepassword.htm",//修改登录密码接口
        setpaypassword:config.domain+"userabout/user/setpaypassword.htm",//修改支付密码接口

        getusercoupon:config.domain+"userabout/user/getusercoupon.htm",//返回优惠券接口

        userorderinfo:config.domain+"userabout/orderelated/userorderinfo.htm",//获取订单详情接口
        uporderrentdate:config.domain+"userabout/orderelated/uporderrentdate.htm",//修改订单租期接口
        usercancelorder:config.domain+"userabout/orderelated/usercancelorder.htm",//取消订单接口
        orderweixiuselect:config.domain+"userabout/orderelated/orderweixiuselect.htm",//维修费用详情接口
        orderselectweiz:config.domain+"userabout/orderelated/orderselectweiz.htm",//违章费用详情接口
        orderselectweiy:config.domain+"userabout/orderelated/orderselectweiy.htm",//违约费用详情接口
        orderselectewai:config.domain+"userabout/orderelated/orderselectewai.htm",//额外费用详情接口

        viewcheckcar:config.domain+"userabout/orderelated/viewcheckcar.htm",//验车详情接口
        stepscomplete:config.domain+"fieldwork/fieldwork/stepscomplete.htm",//确认验车接口

        depositinfo:config.domain+"userabout/orderelated/depositinfo.htm",//押金详情接口
        waitpayinfo:config.domain+"userabout/orderelated/waitpayinfo.htm",//待付详情接口

        creditcardinfo:config.domain+"userabout/orderelated/creditcardinfo.htm",//获取信用卡信息接口
        paymentpasswordcheck:config.domain+"userabout/orderelated/paymentpasswordcheck.htm",//验证交易密码接口
        preauthorizationpay:config.domain+"userabout/orderelated/preauthorizationpay.htm",//押金预授权接口
        newpreauthorizationpay:config.domain+"userabout/orderelated/newpreauthorizationpay.htm",//押金预授权用新卡接口

        userorderpayinfo:config.domain+"userabout/orderelated/userorderpayinfo.htm",//待付支付详情获取接口

        listcartimeinfo:config.domain+"userabout/orderelated/listcartimeinfo.htm",//车时详情接口
        upusercartime:config.domain+"userabout/orderelated/upusercartime.htm",//修改车时接口
        usercancelcartime:config.domain+"userabout/orderelated/usercancelcartime.htm",//取消车时接口

        userchoosecars:config.domain+"userabout/orderelated/userchoosecars.htm",//发布车时返回车辆接口
        userpublishcar:config.domain+"userabout/orderelated/userpublishcar.htm",//发布车时接口
        searchflightinfo:config.domain+"userabout/orderelated/searchflightinfo.htm",//航班接口

        usercartimeinfo:config.domain+"userabout/orderelated/usercartimeinfo.htm",//租车获取时间范围接口
        selectvehicle:config.domain+"userabout/orderelated/selectvehicle.htm",//选车接口
        dateandrent:config.domain+"userabout/orderelated/dateandrent.htm",//车辆详情点击接口
        getuserbalancea:config.domain+"userabout/user/getuserbalancea.htm",//获取余额接口
        availablecoupons:config.domain+"userabout/orderelated/availablecoupons.htm",//获取优惠券接口
        insurancelist:config.domain+"userabout/orderelated/insurancelist.htm",//保险套餐接口
        bookingorder:config.domain+"userabout/orderelated/bookingorder.htm",//下订单接口

        gettokenseed:config.domain+"userabout/mobilecode/gettokenseed.htm",//获取种子接口
        uploadimage:config.domain+"userabout/mobilecode/uploadimage.htm",//拍照上传图片接口
        usecarbandmodels:config.domain+"userabout/orderelated/usecarbandmodels.htm",//获取车辆接口
        selectserviceoutlets:config.domain+"userabout/orderelated/selectserviceoutlets.htm",//获取门店接口
        bankconfig:config.domain+"userabout/orderelated/bankconfig.htm",//获取银行接口
        usercartime:config.domain+"userabout/orderelated/usercartime.htm",//车辆车时信息接口
        userorderlist:config.domain+"userabout/orderelated/userorderlist.htm",//订单列表接口
        usercartimelist:config.domain+"userabout/orderelated/usercartimelist.htm",//车时列表接口
        orderalipay:config.domain+"userabout/orderelated/orderalipay.htm",

        addparkingorder2:config.domain+"/userabout/parking/commitparkorder.htm",
        checkparkingordercar:config.domain+"/userabout/parking/checkcaridentity.htm",
        addnewcar:config.domain+"/userabout/parking/addnewcar.htm",
        calculateparkingprice:config.domain+"/userabout/parking/calculateparkingprice.htm",
        parkingorderalipay:config.domain+"/userabout/parking/parkingorderalipay.htm",
        addparkingorder:config.domain+"/userabout/parking/addparkingorder.htm",
        parkingorderlist:config.domain+"/userabout/parking/parkingorderlist.htm",
        parkingorderinfo:config.domain+"/userabout/parking/parkingorderinfo.htm",
        cancelparkingorder:config.domain+"/userabout/parking/cancelparkingorder.htm",
        updateparkingtime:config.domain+"/userabout/parking/updateparkingtime.htm",
        calculaterent:config.domain+"/userabout/parking/calculaterent.htm",
        menuchangestate:config.domain+"/userabout/user/menuchangestate.htm",
        editpaypassurl:config.domain+"/h5cargo/index/editpaypass.htm",
        weixininfo:config.domain+"h5cargo/nologinindex/getweixininfo.htm",
        getweixinimage:config.domain+"h5cargo/nologinindex/getweixinimage.htm",

       citysupport:config.domain+"/userabout/parking/citysupport.htm",
       flightcitypan:config.domain+"/userabout/parking/flightcitypan.htm"
}


//给title赋值
my.givetitle = function(titles){
    var $body = $('body');
    document.title = titles;
// hack在微信等webview中无法修改document.title的情况
    var $iframe = $('<iframe src="/favicon.ico"></iframe>').on('load', function() {
        setTimeout(function() {
            $iframe.off('load').remove();

        }, 0)
    }).appendTo($body);
}
//判断登陆跳转页面
my.getlogintiaozhuan = function(){
    if(my.getCookie('token') && my.getCookie('id')){
        key=my.get_key(my.getCookie('token'));
        var user_idss={
            'user_id':my.getCookie('id')
        }
        user_idss=JSON.stringify(user_idss);
        user_idss=my.cryptoASEencrypt(user_idss,key).toString();
        $.ajax({
            url: api.menuchangestate,
            type: 'post',
            //async: true,
            data: {
                'api_value': user_idss
            },
            success: function (data) {
            	if(data.match("err_code")!=null){
                switch(JSON.parse(data).err_code)
                {
                    case 40003:
                        my.tokenExpire();
                        break;
                    default:
                        $.toast(JSON.parse(data).err_msg);

                }

             }else{
                data=JSON.parse(data);
                datass=JSON.parse(my.cryptoASEdencrypt(data.data,key));
                console.log(datass[0].atntype);
                if(datass[0].atntype==0){
                    $(".zuche").text('出租');
                    $(".zucheurl").attr("href",'/h5cargo/index/carrental.htm');

                }else{
                  //  $(".zucheurl").attr("href",'/h5cargo/index/rentalcar.htm#page_rentalCar');
                    $(".zucheurl").attr("href",'/h5cargo/index/rentalcar.htm')
                }
            }
             }
        });
            $(".aicheurl").attr("href",'/h5cargo/index/mycarlist.htm#page_mycarlist2');

        }else{
            //未登录时 泊车 租车 爱车管理 的url
        $(".bocheurl").attr("href",'/h5cargo/nologinindex/parkindex.htm');//泊车管理
        $(".zucheurl").attr("href",'/h5cargo/nologinindex/rentalcar.htm');//泊车管理
        $(".aicheurl").attr("href",'/h5cargo/nologinindex/mycarlist.htm');//爱车管理
        //$(".bocheurl").attr("href",'/h5cargo/nologinindex/parkindex.htm#page_noLoginparkIndex');//泊车管理
        //$(".zucheurl").attr("href",'/h5cargo/nologinindex/rentalcar.htm#page_noLoginRentalCar');//泊车管理
        //$(".aicheurl").attr("href",'/h5cargo/nologinindex/mycarlist.htm#page_mycarlist1');//爱车管理
        $(".quanyiurl").attr("href",'/h5cargo/nologinindex/welfare.htm');//福利
        }
    }


my.get_key = function(str){
    if(str==false||my.getCookie('id')==false){
        $.hidePreloader();
        my.setCookie('token','',-1)
        my.setCookie('id','',-1)
        my.setCookie('phone','',-1)
        //$.alert("请先登陆",function(){
        $.router.load(config.domain+'h5cargo/nologinindex/login.htm?return_url=/h5cargo/index/home.htm',true);
        //$.router.load(config.domain+'h5cargo/login/login.htm?return_url=/h5cargo/index/home.htm',true);
        //});
        return;
    }
    var key=null;
    var sessionid=my.getCookie('PHPSESSID');
    key=sessionid+str;
    key=CryptoJS.MD5(key).toString()
    key= CryptoJS.SHA256(key);
    return key;
}
//验证码提交倒计时
my.countdown=function(time,id){  //time：倒计时时间；id:操作元素
            if (time == 0||$(id).attr('data-now')=='1') {
            	$(id).attr('data-now','0')
                $(id).attr('data-submit','1')
                $(id).text("点击获取证码");
                $(id).css({'color':'#fff','backgroundColor':'#0894ec'})
                time = 3;
            } else {
               $(id).attr('data-submit','0')
               $(id).css({'color':'#CAC3D9','backgroundColor':'#EFEDF2','border':'none'})
               time--
               $(id).text("(" + time + ")");
               setTimeout(function(){my.countdown(time,id) },1000)
            }

}
//提交倒计时
my.countSubmit=function(time,id){  //time：倒计时时间；id:操作元素
            if (time == 0) {
               $('.xy-ok').trigger('click')
            } else {
               time--
               $(id).text("(" + time + ")");
               t=setTimeout(function(){my.countSubmit(time,id) },1000)
            }

}
//获取链接参数值
//my.getUrlParam=function(name){  //name:键
//  //构造一个含有目标参数的正则表达式对象
//  var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
//  //匹配目标参数
//  var r = window.location.search.substr(1).match(reg);
//  //返回参数值
//  if (r!=null) return unescape(r[2]);
//  return null;
//}
//设置cookie
my.setCookie = function(name, value, seconds) {
 seconds = seconds || 0;   //seconds有值就直接赋值，
 var expires = "";
 if (seconds != 0 ) {      //设置cookie生存时间
 var date = new Date();
 date.setTime(date.getTime()+(seconds*1000));
 expires = "; expires="+date.toGMTString();
 }
 document.cookie = name+"="+escape(value)+expires+"; path=/";   //转码并赋值
}
//获取cookie
my.getCookie= function(c_name)
{
if (document.cookie.length>0)
  {
     c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1)
    {
       c_start=c_start + c_name.length+1
       c_end=document.cookie.indexOf(";",c_start)
       if (c_end==-1) c_end=document.cookie.length
       return unescape(document.cookie.substring(c_start,c_end))
    }else{
	   return  false
      }
  }else{
  	return false
  }

}
my.get_tokenSeed = function(){
	var tokenSeed=null
    $.ajax({
      		type:"post",
      		url:api.gettokenseed,
      		async:false,
      		success:function(data){
      			if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      							}else{
      							     data=JSON.parse(data)
     							     tokenSeed=data.TokenSeed
      							     my.setCookie('token',data.TokenSeed,'7200')
     							     //sessionStorage.token=data.TokenSeed;
     							    }
      						      },
      		});
    return tokenSeed
}

my.get_key_login = function(str){
	if(str==false){

	    $.alert("服务器错误，请退出重试");
		return;
	}
	var key=null;
	var sessionid=my.getCookie('PHPSESSID');
      	key=sessionid+str;
      	key=CryptoJS.MD5(key).toString()
      	key= CryptoJS.SHA256(key);
    return key;
}
//加密
my.cryptoASEencrypt=function (str,key){
	var str_iv='01040105090200000000000000000605';
    var new_iv='';
    for(var i=0;i<str_iv.length-1;i+=2)
    {
    new_iv+=String.fromCharCode(parseInt(str_iv.substr(i,2), 16));
    }
    var iv  = CryptoJS.enc.Latin1.parse(new_iv);
    var encrypted = CryptoJS.AES.encrypt(str,key, { iv: iv,mode:CryptoJS.mode.CBC, padding:CryptoJS.pad.Pkcs7});
	    encrypted=encrypted.toString().replace(/\+|\=|\//g, function(){
              var config = {
                             '+': '-',
                             '=': '',
                             '/': '_'
                           };
                return config[arguments[0]];
             });
	return encrypted
}
//解密
my.cryptoASEdencrypt = function(str,key){
	var str=str;
    var str_iv='01040105090200000000000000000605';
    var new_iv='';
    for(var i=0;i<str_iv.length-1;i+=2)
     {
      new_iv+=String.fromCharCode(parseInt(str_iv.substr(i,2), 16));
     }
    var iv  = CryptoJS.enc.Latin1.parse(new_iv);
    var decryptd = str.replace(/\-|\_/g, function(){
          var config = {
             '-': '+',
             '_': '/'
            };
            return config[arguments[0]];
        });
    decryptd+='===='.substr(0,decryptd.length %4)
    decryptd = CryptoJS.AES.decrypt(decryptd, key, {
        iv: iv,
        mode:CryptoJS.mode.CBC,
        padding:CryptoJS.pad.Pkcs7
      });
      return decryptd.toString(CryptoJS.enc.Utf8)
}

my.checkLogin=function(){
//	if(my.getCookie('token')==false||my.getCookie('id')==false){
//		my.setCookie('token','',-1)
//      my.setCookie('id','',-1)
//      my.setCookie('phone','',-1)
//		$.alert("种子过期，请重新登陆",function(){
//         $.router.loadPage("login.html");
//      });
//	    return false
//	}else{
//		return true
//	}
return true
}
//token过期操作
my.tokenExpire=function(){
	    my.setCookie('token','',-1)
        my.setCookie('id','',-1)
        my.setCookie('phone','',-1)
	    $.alert("登陆超时，请重新登陆",function(){
        $.router.loadPage("/h5cargo/nologinindex/login.htm");
           // $.router.loadPage("/h5cargo/login/login.htm?return_url=/h5cargo/index/parkindex.htm");
     });
}
//转ASII编码
my.stringToAsii= function (str){
　　　　var val="";
　　　　for(var i = 0; i < str.length; i++){
　　　　　　if(val == "")
　　　　　　　　{val = str.charCodeAt(i)}
　　　　　　else
　　　　　　　 {　val += str.charCodeAt(i)}
　　　　}
　　　　return val
}
my.scollToggleBar=function(){
//	var beforeScoll=$('.page').scrollTop()
//	$('.page').scroll(function(){
//		if($('.page').scrollTop()-beforeScoll>=0)
//		    {
//		    	beforeScoll=$('.page').scrollTop()
//		    	//$('.bar-tab').fadeOut(500)
//		    	$('.bar-tab').stop(true).animate({'height':'0'},200)
//		    }
//		else{
//			    beforeScoll=$('.page').scrollTop()
//			    //$('.bar-tab').fadeIn(500)
//			    $('.bar-tab').stop(true).animate({'height':'2.5rem'},200)
//		    }
//	})
}
function h5_show_photo(da,list){
	var list=JSON.parse(list)
	$.showIndicator()
	$.ajax({
      		type:"post",
      		url:api.uploadimage,
      		async:true,
      		data:{'img_date':da},
      		error:function(){
      			$.hideIndicator()
      			$.toast('请求失败')
      		},
      		success:function(data){
      			       if(data.match("img_name")!=null){
      			           	 $.hideIndicator()
      			       	     data=JSON.parse(data)
      			       	     $(list.id).attr('name',data.img_name)
      			       	     if(list.text!='no'){
      			       	     	$(list.id).addClass('img-upload')
      			       	     	$(list.id).text(list.text+'上传成功(点击重新上传)')
      			       	     	$(list.id).prepend('<img src="/h5car/img/icon/ok_2.png">')
      			       	     }else if(list.text=='no'){
      			       	     	//start
      			       	     	$.confirm('确认上传么？', function () {
                 	    	var info_carEdit_addImg={
      						     //'u_userid':sessionStorage.id,
      						     'u_userid':my.getCookie('id'),
      						     'cars_id':sessionStorage.car_id,
      						     'cars_img':$('.carEdit-img-tj').attr('name'),
      					               }
    					info_carEdit_addImg=JSON.stringify(info_carEdit_addImg)
                        info_carEdit_addImg=my.cryptoASEencrypt(info_carEdit_addImg,key).toString()
                 	    $.ajax({
      					   url:api.uploadcarimg,
      					   type: 'post',
      					   async:true,
      					   data:{
      						      'api_value':info_carEdit_addImg
      					        },
      					    error:function(){
      					    	$.hideIndicator()
      					    	$.router.reloadPage();
      							$.toast("图片上传失败,请重新上传");
      						},
      					    success:function(data){
      						if(data.match("err_code")!=null){
      							$.hideIndicator()
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									    my.tokenExpire()
      									   break;
      									default:
      									   $.router.reloadPage();
      									   $.toast(JSON.parse(data).err_msg);
      								}
      							}else{
      							$.router.reloadPage();
      							$.toast('图片上传成功');

      						}
      					}
      				});
                 	   })
      			       	     	//end
      			       	     }
      			       }else if(data.match("err_code")!=null){
      			       	     $.hideIndicator()
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire();
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      							}else{
      								    $.hideIndicator()
      							        $.toast('上传失败,请重新上传');
      							}

      						      },
      		});
}
function h5_show_point(x,y,t,s){
            //GPS坐标 百度地图API功能
             var ggPoint = new BMap.Point(y,x);
           //地图初始化
             var bm = new BMap.Map("allmap");
                 bm.centerAndZoom(ggPoint, 15);
                 bm.addControl(new BMap.NavigationControl());
           //坐标转换完之后的回调函数
             translateCallback = function (data){
               if(data.status === 0) {
		           var geoc = new BMap.Geocoder()
		           var pt = data.points[0];
		               geoc.getLocation(pt, function(rs){
		           var addComp = rs.addressComponents;
		           var marker = new BMap.Marker(data.points[0]);
                       bm.addOverlay(marker);
                   var label = new BMap.Label(addComp.city+addComp.district+addComp.street+addComp.streetNumber,{offset:new BMap.Size(20,-10)});
                       marker.setLabel(label); //添加百度label
                       bm.setCenter(data.points[0]);
		       });
             }
          }
            setTimeout(function(){
             var convertor = new BMap.Convertor();
             var pointArr = [];
             pointArr.push(ggPoint);
             convertor.translate(pointArr, 1, 5, translateCallback)
            }, 1000);

       }
my.getCars=function(callback){
	var Cars=null
	var info={'u_userid':my.getCookie('id')}
    	info=JSON.stringify(info)
        info=my.cryptoASEencrypt(info,key).toString()
        $.ajax({
      		type:"post",
      		url:api.usecarbandmodels,
      		async:true,
      		data:{
      			    'api_value':info
      						},
      	    error:function(){
      	    	$.hidePreloader()
      	    	$.toast("请求失败");
      	    },
      		success:function(data){
      			if(data.match("err_code")!=null){
      				$.hidePreloader()
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      							}else{

      							      data=JSON.parse(data)
                                      Cars=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      							      callback(Cars)
      							     }
      						      },
      		});
    return Cars
}
my.getStores=function(callback){
	var Stores=null
	var info={'u_userid':my.getCookie('id')}
    	info=JSON.stringify(info)
        info=my.cryptoASEencrypt(info,key).toString()
    $.ajax({
      		type:"post",
      		url:api.selectserviceoutlets,
      		async:true,
      		data:{
      			    'api_value':info
      						},
      		success:function(data){
      			if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      							}else{
      			                    data=JSON.parse(data)
      							    Stores=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      							    callback(Stores)
      							   }
      						      },
      		});
    return Stores
}
my.getBanks=function(callback){
	var Banks=null
	var info={'u_userid':my.getCookie('id')}
    	info=JSON.stringify(info)
        info=my.cryptoASEencrypt(info,key).toString()
        $.ajax({
      		type:"post",
      		url:api.bankconfig,
      		async:true,
      		data:{
      			    'api_value':info
      						},
      		success:function(data){
      			if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      							}else{
      			                    data=JSON.parse(data)
      							    Banks=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      							    callback(Banks)
      							   }
      						      },
      		});
    return Banks
}
my.is_leap=function(year) {
             return (year%100==0?res=(year%400==0?1:0):res=(year%4==0?1:0));
        } //是否为闰年
//my.calendar=function(a,b){   //月份切换a,b现在月份
//	         var nstr=new Date(); //当前Date资讯
//           var ynow=nstr.getFullYear(); //年份
//           var mnow=a; //月份
//           var dnow=nstr.getDate(); //今日日期
//           var n1str=new Date(ynow,mnow,1); //当月第一天Date资讯
//           var firstday=n1str.getDay(); //当月第一天星期几
//           var m_days=new Array(31,28+my.is_leap(ynow),31,30,31,30,31,31,30,31,30,31); //各月份的总天数
//           var tr_str=Math.ceil((m_days[mnow] + firstday)/7); //表格所需要行数
//           for(i=0;i<tr_str;i++) { //表格的行
//               	var tdStr=''
//               for(k=0;k<7;k++) { //表格每行的单元格
//                  idx=i*7+k; //单元格自然序列号
//                  date_str=idx-firstday+1; //计算日期
//                  (date_str<=0 || date_str>m_days[mnow]) ? date_str="&nbsp;" : date_str=idx-firstday+1; //过滤无效日期（小于等于零的、大于月总天数的）
//                   //打印日期：今天底色为红
//                   if(date_str==dnow&&b==mnow){
//                   	tdStr+="<td align='center' id='"+date_str+"' class='now'>今天</td>"
//                   }else{
//                   	tdStr+="<td align='center' id='"+date_str+"'>" + date_str + "</td>"
//                   }
//                }
//               $('.cal-tab').append('<tr>'+tdStr+'</tr>')
//           }
//}
my.changCalDataA=function(a,b){
	         var kezu_s=new Array()
	         var by_s=new Array()
	         for(var i=0;i<b.length;i++){
	     	   for(k in b[i]){
	     		 if(k==a){
	     			if(b[i][k].kezu!=''){kezu_s=kezu_s.concat(b[i][k].kezu)}
	     			if(b[i][k].by!=''){by_s=by_s.concat(b[i][k].by)}

	     		    }
	            }
	         }
	         var CalData='{"kezu":['+kezu_s+'],"by":['+by_s+']}'
//	         if(kezu_s.length==0){
//	         	CalData='{"kezu":"","by":['+by_s+']}'
//	         }
//	         if(by_s.length==0){
//	         	CalData='{"kezu":"","by":""}'
//	         }
	         CalData=JSON.parse(CalData)
	             return CalData

}
my.changCalDataB=function(a,b){
	         var kezu_s=new Array()
	         var by_s=new Array()
	         for(var i=0;i<b.length;i++){
	     	   for(k in b[i]){
	     		 if(k==a){
	     			if(b[i][k].yizu!=''){kezu_s=kezu_s.concat(b[i][k].yizu)}
	     			if(b[i][k].by!=''){by_s=by_s.concat(b[i][k].by)}

	     		    }
	            }
	         }
	         var CalData='{"yizu":['+kezu_s+'],"by":['+by_s+']}'
//	         if(kezu_s.length==0){
//	         	CalData='{"kezu":"","by":['+by_s+']}'
//	         }
//	         if(by_s.length==0){
//	         	CalData='{"kezu":"","by":""}'
//	         }
	         CalData=JSON.parse(CalData)
	             return CalData

}
my.calendar=function(a,b,c,d){   //月份切换a,b现在月份c:可租 d:已租
	         var nstr=new Date(); //当前Date资讯
             var ynow=nstr.getFullYear(); //年份
             var mnow=a; //月份
             var dnow=nstr.getDate(); //今日日期
             var n1str=new Date(ynow,mnow,1); //当月第一天Date资讯
             var firstday=n1str.getDay(); //当月第一天星期几
             var m_days=new Array(31,28+my.is_leap(ynow),31,30,31,30,31,31,30,31,30,31); //各月份的总天数
             var tr_str=Math.ceil((m_days[mnow] + firstday)/7); //表格所需要行数
             //var kezu_date=c[a+1];
             //var yizu_date=d[a+1]
             var kezu_date=my.changCalDataA(a+1,c)
             var yizu_date=d
             if(d.length==0){
             	yizu_date=undefined
             }else{
             	yizu_date=my.changCalDataB(a+1,d)
             }
             for(i=0;i<tr_str;i++) { //表格的行
                 	var tdStr=''
                 for(k=0;k<7;k++) { //表格每行的单元格
                    idx=i*7+k; //单元格自然序列号
                    date_str=idx-firstday+1; //计算日期
                    (date_str<=0 || date_str>m_days[mnow]) ? date_str="&nbsp;" : date_str=idx-firstday+1; //过滤无效日期（小于等于零的、大于月总天数的）
                     //打印日期：今天底色为红
                       if(date_str==dnow&&b==a){
                         var now_str="<td align='center' id='"+date_str+"' class='now'>今天</td>"
                         if(kezu_date!=undefined)
                         {
                         	for(h=0;h<kezu_date.kezu.length;h++)
                       	    {
                       	 	  if(kezu_date.kezu[h]==date_str)
                       	 	    {
                       	          now_str="<td align='center' id='"+date_str+"' class='now check'>今天</td>"
                       	 	    }

                       	    }
                       	    for(h=0;h<kezu_date.by.length;h++)
                       	    {
                       	 	  if(kezu_date.by[h]==date_str)
                       	 	    {
                       	          now_str="<td align='center' id='"+date_str+"' class='now check by-Y'>今天</td>"
                       	 	    }

                       	    }
                         }
                         if(yizu_date!=undefined)
                         {
                         	for(h=0;h<yizu_date.yizu.length;h++)
                       	    {
                       	 	  if(yizu_date.yizu[h]==date_str)
                       	 	    {
                       	          now_str="<td align='center' id='"+date_str+"' class='now check yxz'>今天</td>"
                       	 	    }

                       	    }
                       	    for(h=0;h<yizu_date.by.length;h++)
                       	    {
                       	 	  if(yizu_date.by[h]==date_str)
                       	 	    {
                       	          now_str="<td align='center' id='"+date_str+"' class='now check yxz by-N'>今天</td>"
                       	 	    }

                       	    }
                         }
                     	    tdStr+=now_str

                       }else{
                   	       // tdStr+="<td align='center' id='"+date_str+"'>" + date_str + "</td>"
                   	        var td_str="<td align='center' id='"+date_str+"'>" + date_str + "</td>"
                       	    if(kezu_date!=undefined)
                            {
                         	 for(h=0;h<kezu_date.kezu.length;h++)
                       	     {
                       	 	  if(kezu_date.kezu[h]==date_str)
                       	 	    {
                       	          td_str="<td align='center' id='"+date_str+"' class='check'>" + date_str + "</td>"
                       	 	    }

                       	     }
                       	     for(h=0;h<kezu_date.by.length;h++)
                       	     {
                       	 	  if(kezu_date.by[h]==date_str)
                       	 	    {
                       	          td_str="<td align='center' id='"+date_str+"' class='check by-Y'>" + date_str + "</td>"
                       	 	    }

                       	     }
                            }
                            if(yizu_date!=undefined)
                            {
                         	 for(h=0;h<yizu_date.yizu.length;h++)
                       	     {
                       	 	  if(yizu_date.yizu[h]==date_str)
                       	 	    {
                       	          td_str="<td align='center' id='"+date_str+"' class='check yxz'>" + date_str + "</td>"
                       	 	    }

                       	     }for(h=0;h<yizu_date.by.length;h++)
                       	     {
                       	 	  if(yizu_date.by[h]==date_str)
                       	 	    {
                       	          td_str="<td align='center' id='"+date_str+"' class='check yxz by-N'>" + date_str + "</td>"
                       	 	    }

                       	     }
                            }

                     	    tdStr+=td_str
                       }
                  }
                 $('.cal-tab').append('<tr>'+tdStr+'</tr>')
             }
}

//my.setCalendarY=function(a,b){
//	var m=b+1
////	for(m in a){
//      	    	if(a[m]!=undefined){
//      	    		for(i=0;i<a[m].kezu.length;i++){
//      	                     for(j=0;j<a[m].kezu[i].length;j++)
//      	                     {
//      	                     	       var id='#'+a[m].kezu[i][j]
//      		                           $(id).addClass("check")
//
//      	                     }
//
//                       }
//                      if(a[m].by!=undefined){
//      	    		    for(i=0;i<a[m].by.length;i++){
//      	                     	var id='#'+a[m].by[i]
//      		                     $(id).addClass("by-Y")
//
//                          }
//      	    		}
//      	    	}
//  // }
//}
//my.setCalendarN=function(b,a){
//	var m=a+1
//	//for(m in b){
//      	    	if(b[m]!=undefined){
//      	    		for(i=0;i<b[m].yizu.length;i++){
//      	                     for(j=0;j<b[m].yizu[i].length;j++)
//      	                     {
//      	                     	var id='#'+b[m].yizu[i][j]
//      	                     	$(id).addClass("yxz")
////      	                               if(b[m].chuzu[i].length==1){
////      		                           $(id).addClass("yxz")
////      	                               }else{
////      	                                   if(j==0){
////      		                                 $(id).addClass("check-left")
////     	                                     }else if(j==b[m].chuzu[i].length-1){
////      		                                   $(id).addClass("check-right")
////      	                                      }else{
////      		                                $(id).addClass("check")
////      	                                  }
////      	                                      $(id).addClass("yxz")
////      	                                     }
//
//      	                     }
//
//                       }
//   	    		      if(b[m].by!=undefined){
//      	    		    for(i=0;i<b[m].by.length;i++){
//      	                     	var id='#'+b[m].by[i]
//      		                     $(id).addClass("by-N")
//
//                          }
//      	    		}
//      	    	}
//      	   // }
//}
my.setCalendar=function(id){
	 var now_date=new Date();
                    var now_month=now_date.getMonth()
                    var now_month_h=now_month
	        		var car_data_str=''
	        		var car_data_str_key=0
	        		var car_data_stra=new Array()
	        		var car_data_strb=new Array()
	 var timeinfo={'cars_id':id}
    				    timeinfo=JSON.stringify(timeinfo)
                        timeinfo=my.cryptoASEencrypt(timeinfo,key).toString()
      				    $.ajax({
      					url:api.usercartime,
      					type: 'post',
      					async:false,
      					data:{
      						'api_value':timeinfo
      					},
      					error:function(){
      							$.toast("车时信息获取失败");
      						},
      					success:function(data){
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      							}else{
      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    sessionStorage.timespace=JSON.stringify(data)
      								    var cal_time_list_formServer={
	    	                                             space_area:data.time
	                                                 }
	                //初始化日历开始
	        		var M_days_arry=new Array(31,28+my.is_leap(new Date().getFullYear()),31,30,31,30,31,31,30,31,30,31); //各月份的总天数
	        		var byd=''
	                for(var x=0;x<cal_time_list_formServer.space_area.length;x++ )
	                 {
	    	              var start=cal_time_list_formServer.space_area[x].start
    		              var end=cal_time_list_formServer.space_area[x].end

    		                 if(start.substr(5,2)==end.substr(5,2))
    		                 {
    		                 	var len=end.substr(8,2)-start.substr(8,2)
    		                 	var m=start.substr(8,2)
    		                 	var e=end.substr(8,2)
    		                 	var M=start.substr(5,2)
    		                 	var byd=''
    		                 	if(M.substr(0,1)==0){
    		                 		   	    M=M.replace('0','')
    		                 	}
    		                 	if(m.substr(0,1)==0){
    		                 		   	    m=m.replace('0','')
    		                 	}
    		                 	if(e.substr(0,1)==0){
    		                 		   	    e=e.replace('0','')
    		                 	}
    		                 	if( start.substr(11,2)>=12&&end.substr(11,2)<=15){
    		                 		byd=m+','+e

    		                 	}else if( start.substr(11,2)>=12&&end.substr(11,2)>=15){
    		                 		byd=m

    		                 	}else if( start.substr(11,2)<=12&&end.substr(11,2)<=15){
    		                 		byd=e

    		                 	}

    		                 	for(var i=0;i<len;i++)
    		                 	{
    		                 		var mm=+start.substr(8,2)+i
    		                 		m+=','+(mm+1)
    		                 	}
    		                 	car_data_stra[car_data_str_key]=JSON.parse('{"'+M+'":{"kezu":['+m+'],"by":['+byd+']}}')
    		                 	car_data_str_key++
    		                 }else
    		                 {
    		                 	var lena=end.substr(5,2)-start.substr(5,2)
    		                 	for(var i=0;i<=lena;i++)
    		                 	{
    		                 		if(i==0){
    		                 		   var len_day_start=M_days_arry[start.substr(5,2)-1]-start.substr(8,2)//30或31需要判断
    		                 		   var m_start=start.substr(8,2)
    		                 		   var M=start.substr(5,2)
    		                 	       if(M.substr(0,1)==0){
    		                 		   	    M=M.replace('0','')
    		                 	         }
    		                 		   if(m_start.substr(0,1)==0){
    		                 		   	 m_start=m_start.replace('0','')
    		                 		   }
    		                 		    if( start.substr(11,2)>=12){
    		                 		    byd=m_start
    		                 	        }
    		                 		   if(len_day_start!=0){
    		                 		   	for(var j=0;j<len_day_start;j++)
    		                 	        {
    		                 		      var mm=+start.substr(8,2)+j
    		                 		      m_start+=','+(mm+1)
    		                 	        }
    		                 		   }
    		                 	       car_data_stra[car_data_str_key]=JSON.parse('{"'+M+'":{"kezu":['+m_start+'],"by":['+byd+']}}')
                                       car_data_str_key++
    		                 		}else if(i==lena){
    		                 		    var len_day_end=end.substr(8,2)
    		                 	        var m_end=end.substr(8,2)
    		                 	        var M=end.substr(5,2)
    		                 	        if(M.substr(0,1)==0){
    		                 		   	    M=M.replace('0','')
    		                 	        }
    		                 	        if(m_end.substr(0,1)==0){
    		                 		   	    m_end=m_end.replace('0','')
    		                 		    }
    		                 	        if(end.substr(11,2)<=15){
    		                 		      byd=m_end
    		                 	        }
    		                 	        for(var j=1;j<len_day_end;j++)
    		                 	        {
    		                 		       var mm=+end.substr(8,2)-j
    		                 		       m_end+=','+mm
    		                 	        }
    		                 	        car_data_stra[car_data_str_key]=JSON.parse('{"'+M+'":{"kezu":['+m_end+'],"by":['+byd+']}}')
    		                 	       car_data_str_key++

    		                 		}else{
    		                 	        var m_len=0
    		                 	        for(var j=1;j<=31;j++)
    		                 	        {
    		                 		      m_len+=','+j
    		                 	        }
    		                 	        var n_m=start.substr(5,2)
    		                 	        if(n_m.substr(0,1)==0){
    		                 		   	    n_m=+n_m.replace('0','')+i
    		                 		    }else{
    		                 		    	n_m=+n_m+i
    		                 		    }
    		                 	        car_data_stra[car_data_str_key]=JSON.parse('{"'+n_m+'":{"kezu":['+m_len+'],"by":""}}')
    		                 	        car_data_str_key++
    		                 		}

    		                 	}

    		                 }
	                      }

                    //初始化日历结束
                    my.calendar(now_month,now_month,car_data_stra,car_data_strb)
                    $('.now-month').text(now_month+1+"月")
      					}
      				}
      			});
      			return  car_data_stra


}
my.getRentalCarOrderList=function(user_id,page_size,page_now,key,type){
	                var RentalCarOrderList=''
                    var orderinfo={
      					   user_id:user_id,
      					   page_size:page_size,
      					   page_now:page_now,
      					   type:type
      					}
      				orderinfo=my.cryptoASEencrypt(JSON.stringify(orderinfo),key)
      				$.ajax({
      					url:api.userorderlist,
      					type: 'post',
      					async:false,
      					data:{
      						'api_value':orderinfo
      					},
      					error:function(){
      							$.toast("订单列表获取失败");
      						},
      					success:function(data){
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									  my.tokenExpire()
      									   break;
      									case 50304:
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						}else{
      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    RentalCarOrderList=data


      							 }
      					}
      				})
      				return  RentalCarOrderList

}
my.getCarRentalOrderList=function(user_id,page_size,page_now,key,type){
	                var CarRentalOrderList=''
                    var orderinfo={
      					   user_id:user_id,
      					   page_size:page_size,
      					   page_now:page_now,
      					   type:type
      					}
      				orderinfo=my.cryptoASEencrypt(JSON.stringify(orderinfo),key)
      				$.ajax({
      					url:api.usercartimelist,
      					type: 'post',
      					async:false,
      					data:{
      						'api_value':orderinfo
      					},
      					error:function(){
      							$.toast("订单列表获取失败");
      						},
      					success:function(data){
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									case 50304:
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						}else{
      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								   CarRentalOrderList=data


      							 }
      					}
      				})
      				return  CarRentalOrderList

}
my.getParkOrderList=function(user_id,page_size,page_now,key,type){
	                var ParkOrderList=''
                    var orderinfo={
      					   user_id:user_id,
      					   page_size:page_size,
      					   page_now:page_now,
      					   type:type
      					}
      				orderinfo=my.cryptoASEencrypt(JSON.stringify(orderinfo),key)
      				$.ajax({
      					url:api.parkingorderlist,
      					type: 'post',
      					async:false,
      					data:{
      						'api_value':orderinfo
      					},
      					error:function(){
      							$.toast("订单列表获取失败");
      						},
      					success:function(data){
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									case 50304:
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						}else{
      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    ParkOrderList=data


      							 }
      					}
      				})
      				return  ParkOrderList

}

////////////////////////////////////////用户账户明细开始////////////////////////////////////////
my.getUserAccountDetailList=function(user_id,start_date,end_date,page_number,page_size,key){// 用户编号 搜索开始时间 搜索结束时间 页数 每页数据数目
    var UserAccountDetailList='';
    var useraccountinfo={
        user_id:user_id,
        start_date:start_date,
        end_date:end_date,
        page_number:page_number,
        page_size:page_size
    };
   // return useraccountinfo;
    useraccountinfo=my.cryptoASEencrypt(JSON.stringify(useraccountinfo),key);
    $.ajax({
        url:api.getaccountdetails,
        type: 'post',
        async:false,
        data:{
            'api_value':useraccountinfo
        },
        error:function(){
            $.alert("账户明细加载失败");
        },
        success:function(data){
            if(data.match("err_code")!=null){
                switch(JSON.parse(data).err_code)
                {
                	case 40003:
      									   my.tokenExpire()
      									   break;
                    default:
                        $.alert(JSON.parse(data).err_msg);
                }
            }else{
                data=JSON.parse(data);
                data=JSON.parse(my.cryptoASEdencrypt(data.data,key));
                UserAccountDetailList=data;


            }
        }
    })
    return  UserAccountDetailList

}

////////////////////////////////////////////用户账户明细 结束//////////////////////////////////////////
//截取链接数据
my.getUrlParam=function(name) {
                  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                  var r = window.location.search.substr(1).match(reg);  //匹配目标参数
                     if (r != null) return unescape(r[2]); return null; //返回参数值
                  }
//时间格式转换
my.parserDate = function (date) {
                        var t = Date.parse(date);
                     if (!isNaN(t)) {
                         return new Date(Date.parse(date.replace(/-/g, "/")));
                       } else {
                          return new Date();
                         }
                       };
//刷新当前页面
my.reload=function() {
	var id='#'+$('.page-current').attr('id')
    $(id).trigger('pageInit');
}
//////////////////////////////////////////航班查询获取城市//////////////////////////////
my.citySupport=function(callback){
    var info={
    	user_id:my.getCookie('id')
    }
    info=my.cryptoASEencrypt(JSON.stringify(info),key);
	$.ajax({
        url:api.citysupport,
        type: 'post',
        async:true,
        data:{
            'api_value':info
        },
        error:function(){
        	$.hidePreloader()
            $.alert("请求失败~error");
        },
        success:function(data){

            if(data.match("err_code")!=null){
            	$.hidePreloader()
                switch(JSON.parse(data).err_code)
                {
                	case 40003:
      					my.tokenExpire()
      			    break;
                    default:
                        $.alert(JSON.parse(data).err_msg);
                }
            }else{
                data=JSON.parse(data);
                data=JSON.parse(my.cryptoASEdencrypt(data.data,key));
                callback(data)

            }
        }
        })
}
